package com.atelier.plugin.database.domain;

import com.atelier.plugin.database.domain.DatabaseType;
import com.atelier.plugin.database.util.DefaultNamingUtil;
import com.intellij.util.xmlb.annotations.Transient;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;

@Data
public class DatabaseConnectionInfo {
    private String uuid;
    private String databaseName;
    private String url;
    private String username;
    @Transient
    private String password;
    private String host;
    private String port;
    private String name;
    private DatabaseType databaseType; // 数据库类型
    private String driverVersion; // 驱动版本
    private Boolean state;
    @Transient
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public DatabaseConnectionInfo() {

        uuid = UUID.randomUUID().toString();
    }

    // 构造函数
    public DatabaseConnectionInfo(String databaseName, String url, String username, String password, String host, String port, String name, DatabaseType databaseType, String driverVersion) {
        uuid = UUID.randomUUID().toString();
        this.databaseName = databaseName;
        this.url = url;
        this.username = username;
        this.password = password;
        this.host = host;
        this.port = port;
        this.name = name;
        this.databaseType = databaseType;
        this.driverVersion = driverVersion;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        DatabaseConnectionInfo that = (DatabaseConnectionInfo) o;

        if (!Objects.equals(databaseName, that.databaseName)) return false;
        if (!Objects.equals(url, that.url)) return false;
        if (!Objects.equals(username, that.username)) return false;
        if (!Objects.equals(password, that.password)) return false;
        if (!Objects.equals(host, that.host)) return false;
        if (!Objects.equals(port, that.port)) return false;
        if (!Objects.equals(name, that.name)) return false;
        if (databaseType != that.databaseType) return false;
        return Objects.equals(driverVersion, that.driverVersion);
    }

    @Override
    public int hashCode() {
        int result = databaseName != null ? databaseName.hashCode() : 0;
        result = 31 * result + (url != null ? url.hashCode() : 0);
        result = 31 * result + (username != null ? username.hashCode() : 0);
        result = 31 * result + (password != null ? password.hashCode() : 0);
        result = 31 * result + (host != null ? host.hashCode() : 0);
        result = 31 * result + (port != null ? port.hashCode() : 0);
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (databaseType != null ? databaseType.hashCode() : 0);
        result = 31 * result + (driverVersion != null ? driverVersion.hashCode() : 0);
        return result;
    }
}
